package com.sky.mapper;


import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DishMapper {
    List<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    @Update("update dish set status = #{status} where id = #{id}")
    void updateStatus(Integer status, Long id);

    @Delete("delete from dish where id = #{id}")
    void delete(Long id);

    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);

    @AutoFill(value = OperationType.INSERT)
    @Insert("insert into dish (name, category_id, price, image,description, status, create_time, update_time, create_user, update_user) " +
            "values (#{name}, #{categoryId}, #{price}, #{image},#{description}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void addDish(Dish dish);

    @Insert("insert into dish_flavor (dish_id, name, value) values (#{dishId}, #{name}, #{value})")
    void addDishFlavor(DishFlavor dishFlavor);

    @AutoFill(value = OperationType.UPDATE)
    @Update("update dish set name = #{name}, category_id = #{categoryId}, price = #{price}, image = #{image},description = #{description}, update_time = #{updateTime}, update_user = #{updateUser} where id = #{id}")
    void update(Dish dishDTO);

    @Delete("delete from dish_flavor where dish_id = #{id}")
    void deleteFlavors(Long id);

    @Select("select * from dish_flavor where dish_id = #{id}")
    List<DishFlavor> getFlavors(Long id);

    @Select("select name from category where id = #{categoryId}")
    String getCategoryName(Long categoryId);

    @Select("select * from dish where category_id = #{categoryId} and status = 1")
    List<DishVO> getDishByCategoryId(Long categoryId);
}
